home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0013_Bit Map scaler.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  2KB  |  98 lines

  1. {
  2. SEAN PALMER
  3.  
  4. Well, I got a wild hair up my butt and decided to convert that
  5. bitmap scaler I posted into an inline assembler procedure (mostly)
  6. It's now quite a bit faster...
  7.  
  8. by Sean Palmer
  9. public domain
  10. }
  11.  
  12. {bitmaps are limited to 256x256 (duh)}
  13.  
  14. type
  15.   fixed = record
  16.     case boolean of
  17.       true  : (w : longint);
  18.       false : (f, i : word);
  19.     end;
  20.  
  21. const
  22.   bmp : array [0..3, 0..3] of byte =
  23.     ((0, 1, 2, 3),
  24.      (1, 2, 3, 4),
  25.      (2, 3, 4, 5),
  26.      (3, 4, 5, 6));
  27. var
  28.   bmp2 : array [0..63, 0..63] of byte;
  29.   i, j : integer;
  30.  
  31. procedure scaleBitmap(var bitmap; x, y : byte; x1, y1, x2, y2 : word);
  32. var
  33.   s, w, h    : word;  {xSkip,width,height}
  34.   sx, sy, cy : fixed; {xinc, yinc, ySrcPos}
  35. begin
  36.   w    := x2 - x1 + 1;
  37.   h    := y2 - y1 + 1;
  38.   sx.w := x * $10000 div w;
  39.   sy.w := y * $10000 div h;
  40.   s    := 320-w;
  41.   cy.w := 0;
  42.   asm
  43.     push ds
  44.     mov  ds, word ptr bitmap+2;
  45.     mov  ax, $A000
  46.     mov  es, ax  {setup screen seg}
  47.     cld
  48.     mov  ax, 320
  49.     mul  y1
  50.     add  ax, x1
  51.     mov  di, ax {calc screen adr}
  52.    @L2:
  53.     mov  ax, cy.i
  54.     mul  x
  55.     mov  bx, ax
  56.     add  bx, word ptr bitmap {offset}
  57.     mov  cx, w
  58.     mov  si, 0     {fraction of src adr (bx.si)}
  59.     mov  dx, sx.f
  60.    @L:
  61.     mov  al, [bx]
  62.     stosb
  63.     add  si, dx
  64.     adc  bx, sx.i    {if carry or sx.i<>0, new source pixel}
  65.     loop @L
  66.     add  di, s     {skip to next screen row}
  67.     mov  ax, sy.f
  68.     mov  bx, sy.i
  69.     add  cy.f, ax
  70.     adc  cy.i, bx
  71.     dec  word ptr h
  72.     jnz  @L2
  73.     pop  ds
  74.   end;
  75. end;
  76.  
  77. begin
  78.   for i := 0 to 63 do   {init bmp2}
  79.     for j := 0 to 63 do
  80.       bmp2[j, i] := j + (i xor $19) + 32;
  81.   asm
  82.     mov ax, $13
  83.     int $10
  84.   end;   {init vga mode 13h}
  85.   for i := 2 to 99 do                 {test bmp}
  86.     scaleBitMap(bmp, 4, 4, 0, 0, i * 2 - 1, i * 2 - 1);
  87.   for i := 99 downto 2 do
  88.     scaleBitMap(bmp, 4, 4, 0, 0, i * 2 - 1, 197);
  89.   for i := 1 to 66 do                 {test bmp2}
  90.     scaleBitMap(bmp2, 64, 64, 0, 0, i * 2 - 1, i * 3 - 1);
  91.   for i := 66 downto 1 do
  92.     scaleBitMap(bmp2, 64, 64, 0, 0, i * 2 - 1, i * 2 - 1 + 66);
  93.   asm
  94.     mov ax, $3
  95.     int $10
  96.   end;      {restore text mode}
  97. end.
  98.